package com.zj.core.tools

import android.app.Activity
import android.content.Context
import android.os.Environment
import com.fileutils.SPUtils
import com.zj.core.base.BaseApplication
import java.io.File
import java.util.*

/**
 * 日期：2019年3月16日
 * 公司：北京子杰宝贝科技有限公司
 * 地址：北京市朝阳区朝阳农场
 * 开发者：达选文
 *
 *
 * 主体功能：基础常量类
 */
@Suppress("DEPRECATION")
class Constant {
    companion object {
        /**
         * IP配置
         */
        //外网：120.27.8.35      //:8080
        //内网：192.168.1.118:7080
        val BASE_URL_HEARD = "http://"
        val BASE_IP = "120.27.8.35"
        val BASE_SYMBOL = ":"
        val BASE_HOST = "7080"
        var BASE_WHOLE_URL = "base_whole_url"         //SP  key

        /**
         * 拼接完整的url
         *
         * @return
         */
        val wholeUrl: String
            get() {
                var mBaseUrl: String = SPUtils.get(
                    BaseApplication.context!!,
                    BASE_WHOLE_URL, "") as String
                if (mBaseUrl != "") {
                    return if (!mBaseUrl.contains(BASE_URL_HEARD)) {
                        BASE_URL_HEARD + mBaseUrl
                    } else {
                        mBaseUrl
                    }
                } else {
                    if (BASE_HOST != "") {
                        mBaseUrl = BASE_URL_HEARD + BASE_IP + BASE_SYMBOL + BASE_HOST
                    } else {
                        mBaseUrl = BASE_URL_HEARD + BASE_IP
                    }
                    return mBaseUrl
                }
            }

        /**
         * 设备标识
         */
        private val LAIJIA_TAIXIN = "HL"         //莱家胎心仪
        private val YUYUE_XUEYA = "PY"           //鱼跃血压计
        private val BAOLAITE_XUEYANG= "OB"       //宝莱特血氧
        private val XIANGSHAN1_TIZHONG = "SX"    //香山体重秤
        private val XUETANG_YUYUE = "GY"         //鱼跃血糖
        private var GAOMU_EWEN = "TH"            //高姆额温枪
        private val JIAYU_GUAGOUTIZHONG = "SH"   //挂钩体重秤-佳域顺芯
        private var JK_EWEN = "TM"               //JK耳温枪

        val SELF_CONNECT_BLE = "self_connect_ble"          //蓝牙自动连接
        val MANUAL_CONNECT_BLE = "manual_connect_ble"      //蓝牙手动连接
        var TEXT_SIZE_KEY = "text_size_key"                //获取字号
        var DETAIL_ADD_KEY="detail_add_key"                //新增数据TAG
        var DETAIL_ADD_STATUS="detail_change_tag"          //新增或修改
        var RECORD_DETAIL_KEY="record_detail_key"          //患者详情TAG
        var NURSE_LIST_KEY="nurse_list_key"                //护士操作记录
        var NURSE_DETAIL_KEY="nurse_detail_key"
        var PICTURE_RES_KEY="picture_res_key"              //照片TAG
        var UPDATE_MES_KEY="update_mes_key"                //更新

        val TAG_GLOBAL="com.zj.global.receiver"            //全局广播
        val TIME_DIFFERENCE:Long=10*60*1000                 //操作间隔

        var REQUEST_RECORD_RES_KEY=3002                //数据录入TAG
        var RESULT_RECORD_SKY=3006                     //数据录入界面返回
        var REQUEST_PICTURE_KEY=3003                   //进入相册界面
        var REQUEST_CAMERA_KEY=3004                    //进入相机界面
        var RQSULT_CAMERA_KEY=3005                     //相机返回
        var MEAUSE_TEXT_VALUE="measure_text"
        var NOTIFY_VOICE_KEY = "notify_voice_key"        //声音开关
        var MODEL_VOICE_KEY = "model_voice_key"        //模型开关
        var UPDATE_VERSION_DATE="2019.06.25"                 //版本更新日期

        var meuseTextViewWidth=339                           //textview默认宽度

        var PATTERN_FETAL_STRING="LOA|LOT|LOP|ROA|ROT|ROP|LMA|LMT|LMP|RMT|RMA|RMP|LSA|LST|LSP|RSA|RST|RSP|LScA|LScP|RScA|RScP"                       //胎方位统一管理吧

        /**
         * 下载存储路径
         */
        var packagePath:String=Environment.getExternalStorageDirectory().toString() +File.separator+"Android"+File.separator+"data"+File.separator+"com.zj.datacoll"+File.separator

        /**
         * 文件存储路径
         */
        var downloadPath:String=Environment.getExternalStorageDirectory().toString() +File.separator+"Download"+File.separator

        fun getVersionMes(context: Context?):Properties{
            val properties = Properties()
            properties.load(context?.assets?.open("version.properties"))
            return properties
        }

        /**
         * 医疗设备UUID
         * 规定格式为：{“mac”:"ServiceUUID:WriteUUID:NotifyUUID:设备类型"}
         *
         *
         * 设备类型：
         * 0：莱家胎心仪
         * 1：血压仪
         * 2：额温枪
         * 3：血氧
         * 4：婴儿体重秤
         * 5、挂钩秤
         * 6、鱼跃血糖仪
         * 7、JK耳温枪
         */
        var DERIVE_UUID_VALUE: HashMap<String, String> = object : HashMap<String, String>() {
            init {
                put(
                    LAIJIA_TAIXIN,
                    "00005500-d102-11e1-9b23-00025b00a5a5:00005501-d102-11e1-9b23-00025b00a5a5:00005501-d102-11e1-9b23-00025b00a5a5:0"
                )                //多普勒胎心仪

                put(YUYUE_XUEYA, "00001810-0000-1000-8000-00805f9b34fb:00002a35-0000-1000-8000-00805f9b34fb:2A35:1")

                put(
                    GAOMU_EWEN,
                    "000018f0-0000-1000-8000-00805f9b34fb:00002af0-0000-1000-8000-00805f9b34fb:00002af1-0000-1000-8000-00805f9b34fb:2"
                )

                put(
                    BAOLAITE_XUEYANG,
                    "0000ffe0-0000-1000-8000-00805f9b34fb:0000ffe1-0000-1000-8000-00805f9b34fb:0000ffe2-0000-1000-8000-00805f9b34fb:3"
                )

                put(
                    XIANGSHAN1_TIZHONG,
                    "0000ffb0-0000-1000-8000-00805f9b34fb:0000ffb2-0000-1000-8000-00805f9b34fb:0000ffb1-0000-1000-8000-00805f9b34fb:4"
                )
                put(
                    JIAYU_GUAGOUTIZHONG,
                    "0000fff0-0000-1000-8000-00805f9b34fb:0000fff1-0000-1000-8000-00805f9b34fb:0000fff2-0000-1000-8000-00805f9b34fb:5"
                )
                put(
                    XUETANG_YUYUE,
                    "00001808-0000-1000-8000-00805f9b34fb:00002a18-0000-1000-8000-00805f9b34fb:00002a52-0000-1000-8000-00805f9b34fb:6"
                )
                put(
                    JK_EWEN,
                    "0000ffb0-0000-1000-8000-00805f9b34fb:0000ffb2-0000-1000-8000-00805f9b34fb:0000ffb2-0000-1000-8000-00805f9b34fb:7"
                )
            }
        }

        /**
         * 裁剪图片存放地址
         *
         * @param activity
         * @return
         */
        fun fileSavePath(activity: Activity, fileName: String): File {
            var fileName = fileName
            if (fileName != "") {
                fileName = "$fileName.jpg"
            }
            return File(activity.getExternalFilesDir("img"), fileName)
        }
    }
}
